﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using KPIS.GERP.SERVICE.DAL;
using KPIS.GERP.SERVICE.Demo.Classes;
using KPIS.GERP.SERVICE.Model;
using Telerik.Web.UI;

namespace KPIS.GERP.SERVICE.Demo.Ekk.MySampleFlow
{
    public partial class AbsenceDetails : Page
    {
        private readonly Employee _employeeDal = new Employee();
        public string Mode { get { return Request["mode"]; } }

        protected void Page_Load(object sender, EventArgs e)
        {
            new SsMng().CheckUss();
            

            if (Mode == null)
                RedirectMode("vs"); 

            if (!Page.IsPostBack)
            { 
                LoadGridAbsenceRequest();
                Page.DataBind();
            }
        }

        public void RedirectMode(string mode)
        {
            if (mode == null)
                mode = "vs";
            
            HttpContext.Current.Response.Redirect("AbsenceDetails.aspx?mode=" + mode);
        } 

        private void LoadGridAbsenceRequest()
        {
            var ds = new Absence().GetHrmPsAbsence(null,null, new SsMng().EmpSeq, null, true, true);
            
            RadGrid1.DataSource = ds;

            if (RadGrid1.CurrentPageIndex < (ds.Count / RadGrid1.PageSize))
                RadGrid1.CurrentPageIndex = (ds.Count / RadGrid1.PageSize);

            RadGrid1.DataBind();
        }
          
        protected void link1_Click(object sender, EventArgs e)
        {
            RedirectMode(Mode == "vs" ? "iis" : "vs");
        }

        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            var ds = new Absence().GetHrmPsAbsence(null, null, new SsMng().EmpSeq, null, true, true);
            RadGrid1.DataSource = ds;
        }
         
    }
} 